﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ERP_InStoreAddCargo.aspx.cs"
    Inherits="CRM_Store_ERP_InStoreAddCargo" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../css/PageStyle.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../JavaScript/Common.js"></script>
    <script type="text/javascript">
        function OnBtnSaveClick(type) {
            if (extcomb_DetailId.getValue() == "") {
                Ext.Msg.alert("提示", "请选择商品")
                return;
            }
            if (extnumf_Nums.getValue() == "" || extnumf_Nums.getValue() < 1) {
                Ext.Msg.alert("提示", "数量不能为空")
                return;
            }
            var str = {
                //CargoId: exthid_ItemlId.getValue(),
                DetailId: extcomb_DetailId.getValue(),
                BatchNo: exttxtf_BatchNo.getValue(),
                Count: extnumf_Nums.getValue(),
                ProduceDate: Ext.util.Format.date(extdate_ProduceDate.getValue(), 'Y/m/d'),
                DisinfectionDate: Ext.util.Format.date(extdate_DisinfectionDate.getValue(), 'Y/m/d'),
                ExpiryDate: Ext.util.Format.date(extdate_ExpiryDate.getValue(), 'Y/m/d'),
                AsepticDate: Ext.util.Format.date(extdate_AsepticDate.getValue(), 'Y/m/d'),
                HAS_VALID: disp_CQYX1.hidden
            };
            if (disp_CQYX1.hidden && !extdate_ExpiryDate.getValue()) {
                Ext.Msg.alert('系统提示', '有效期必须为长期有效或固定日期！');
                return;
            }
            
            if (type == "save")
                Ext.net.DirectMethods.SaveInfo(str);
            else
                Ext.net.DirectMethods.CounSaveInfo(str);
        }

        function Clear() {
            exttxtf_bar_code.setValue("");
            exttxtf_SERIALNO.setValue("");
        }

        function Onextcomb_CURRENCYNAME_select() {
            Ext.net.DirectMethods.SetCombCurrentnameSelect(extcomb_DetailId.value);
        }

        function Onextcomb_CURRENCYNAME_BeforeSelect() {
            if (extcomb_DetailId.mimicing == false)
                return false;
        }
        function SearchOperate() {
            store.reload();
        }

        function SearchOperate2() {
            
            if (extcomb_DetailId.text == "") {
                store.reload();
            }
        }
        
        //function comboxKeyUp() {
        //    ClearCtrlValuesNoClear(Container1, ["extcomb_CURRENCYNAME", "extnumf_Nums"]);
        //    extnumf_Nums.setValue(1);
        //}

        function check_valid_date(cbx) {
            if (cbx.checked) {
                extspin_valid_limit.show();
                disp_text1.show();
                extdate_ExpiryDate.show();
                disp_CQYX1.hide();
            }
            else {
                extspin_valid_limit.hide();
                disp_text1.hide();
                extdate_ExpiryDate.hide();
                disp_CQYX1.show();
            }
        }

        function tmsValueChange(tms, limitField, tmeField) {
            var limit = limitField.getValue();
            if (limit) {
                var newTMe = tms.add(Date.MONTH, limit).add(Date.DAY, -1);
                tmeField.setValue(newTMe);
            }
        }
        
        function tmeValueChange(tme, limitField, tmsField) {
            var tms = tmsField.getValue();
            if (tms) {
                var mths = getMonths(tms, tme);
                limitField.setValue(mths);
            }

        }

        function limitValueChange(limit, tmsField, tmeField) {
            var tms = tmsField.getValue();
            if (tms && limit) {
                var newTMe = tms.add(Date.MONTH, limit).add(Date.DAY, -1);
                tmeField.setValue(newTMe);
            }
            extBtn_Save.enable(); 
            Button2.enable();
        }
        
        //获取月份差
        function getMonths(tms, tme) {
            var mths = 0;
            var tmp = tms;
            for (; tmp < tme.add(Date.DAY, 2); ) {
                tmp = tmp.add(Date.MONTH, 1);
                mths++;
            }
            if (mths > 0)
                mths--;
            return mths;
        }
        
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" AjaxViewStateMode="Enabled" />
    <ext:Viewport ID="Viewport1" runat="server">
        <Content>
            <ext:BorderLayout ID="BorderLayout1" runat="server">
                <Center>
                    <ext:FormPanel ID="Panel2" runat="server" Layout="FitLayout" Border="false" Padding="5">
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <ext:Button ID="Button2" runat="server" Text="继续增加" Icon="Accept">
                                        <Listeners>
                                            <Click Handler=" if (FieldEmptyCheck2(Container1)) OnBtnSaveClick('counsave'); else return false;" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="extBtn_Save" runat="server" Text="确定" Icon="Accept">
                                        <Listeners>
                                            <Click Handler=" if (FieldEmptyCheck2(Container1)) OnBtnSaveClick('save'); else return false;" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="extBtn_Close" runat="server" Text="关闭" Icon="Cancel">
                                        <Listeners>
                                            <Click Handler="Closepopwin2('CargoSelect');" />
                                        </Listeners>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <Content>
                            <ext:Container ID="Container1" runat="server" Layout="ColumnLayout" >
                                <Items>
                                    <ext:Container ID="Container2" runat="server" LabelAlign="Right" Layout="FormLayout" ColumnWidth="0.5">
                                        <Items>
                                            <ext:ComboBox runat="server" ID="extcomb_DetailId" AnchorHorizontal="0.95" AllowBlank="false"
                                                FieldLabel="<font color='red' >*</font>物品名称"
                                                DisplayField="CargoName" ValueField="DetailId" TypeAhead="false" LoadingText="Searching..."
                                                ForceSelection="true" TriggerAction="ALL" EmptyText="请输入汉字或拼音简码" Mode="Remote"
                                                ItemSelector="div.search-item" MinChars="1" ListWidth="650" TabIndex="1" PageSize="10">
                                                <Template ID="Template3" runat="server">
                                                    <Html>
                                                    <table width="100%" style="background-color: #f0f0f0; font-size: small; font-weight: bold">
                                                        <tr>
                                                            <td style="width: 17%;">
                                                                商品名称
                                                            </td>
                                                            <td style="width: 17%;">
                                                                规格
                                                            </td>
                                                            <td style="width: 17%;">
                                                                型号
                                                            </td>
                                                            <td style="width: 17%;">
                                                                生产厂家
                                                            </td>
                                                            <td style="width: 16%;">
                                                                产地
                                                            </td>
                                                            <td style="width: 16%;">
                                                                供应价
                                                            </td>
                                                        </tr>
                                                    </table>
                                                    <tpl for=".">
                                                      <div class="search-item">
                                                          <table width="100%">
                                                              <tr>
                                                                  <td style="width:17%; ">{CargoName}</td>
                                                                  <td style="width:17%; ">{Spec}</td>
                                                                  <td style="width:17%; ">{Version}</td>
                                                                  <td style="width:17%; ">{ProduceName}</td>
                                                                  <td style="width:16%; ">{Area}</td>
                                                                  <td style="width:16%; ">{Supplyprice}</td>
                                                              </tr>
                                                          </table>
                                                      </div>
                                                    </tpl>
                                                    </Html>
                                                </Template>
                                                <Listeners>
                                                    <Change Fn="SearchOperate" />
                                                    <KeyDown Fn="SearchOperate2" />
                                                    <Expand Fn="SearchOperate" />
                                                    <%--<KeyUp Fn="comboxKeyUp" />--%>
                                                    <Select Fn="Onextcomb_CURRENCYNAME_select" />
                                                    <BeforeSelect Fn="Onextcomb_CURRENCYNAME_BeforeSelect" />
                                                </Listeners>
                                                <Store>
                                                    <ext:Store runat="server" ID="store" OnRefreshData="MyData_Refresh" RemotePaging="true">
                                                        <Proxy>
                                                        <ext:PageProxy></ext:PageProxy>
                                                        </Proxy>
                                                        <Reader>
                                                            <ext:JsonReader IDProperty="DetailId">
                                                                <Fields>
                                                                    <ext:RecordField Name="DetailId" Type="Int" />
                                                                    <ext:RecordField Name="CargoId" Type="Int" />
                                                                    <ext:RecordField Name="SupplyId" Type="Int" />
                                                                    <ext:RecordField Name="Supplyprice" Type="Float" />
                                                                    <ext:RecordField Name="State" Type="Int" />
                                                                    <ext:RecordField Name="Remark" />
                                                                    <ext:RecordField Name="CargoName" />
                                                                    <ext:RecordField Name="Spell" />
                                                                    <ext:RecordField Name="ByName" />
                                                                    <ext:RecordField Name="CargoCode" />
                                                                    <ext:RecordField Name="Spec" />
                                                                    <ext:RecordField Name="Version" />
                                                                    <ext:RecordField Name="ProduceName" />
                                                                    <ext:RecordField Name="Area" />
                                                                </Fields>
                                                            </ext:JsonReader>
                                                        </Reader>
                                                    </ext:Store>
                                                </Store>
                                            </ext:ComboBox>
                                            <ext:TextField ID="exttxtf_BatchNo" runat="server" AnchorHorizontal="0.95" TabIndex="3"
                                                FieldLabel="批号">
                                                <DirectEvents>
                                                    <KeyPress OnEvent="Exttxtf_BatchNo_Change" />
                                                    <Change OnEvent="Exttxtf_BatchNo_Change" />
                                                </DirectEvents>
                                            </ext:TextField>
                                            <ext:TextField ID="exttxtf_ByName" runat="server" AnchorHorizontal="0.95" FieldLabel="别名"
                                                ReadOnly="true" StyleSpec="background:#fffbf0;" />
                                            <ext:TextField ID="exttxtf_ProduceName" runat="server" AnchorHorizontal="0.95" FieldLabel="生产厂家"
                                                ReadOnly="true" StyleSpec="background:#fffbf0;" />
                                            <ext:TextField ID="exttxtf_SupplyName" runat="server" AnchorHorizontal="0.95" FieldLabel="供货商"
                                                ReadOnly="true" StyleSpec="background:#fffbf0;" />
                                            <ext:NumberField ID="extnumf_Nums" runat="server" AnchorHorizontal="0.95" DecimalPrecision="0" Text="1" FieldLabel="<font color='red' >*</font>数量" />
                                            <ext:DateField ID="extdate_ProduceDate" runat="server" AnchorHorizontal="0.95" FieldLabel="<font color='red' >*</font>生产日期" 
                                                AllowBlank="false" EmptyText="输入日期格式(年-月-日)：2015-01-01" TabIndex="4" > 
                                                <Listeners>
                                                    <Change Handler="tmsValueChange(newValue,extspin_valid_limit,extdate_ExpiryDate)" />
                                                    <Select Handler="tmsValueChange(date,extspin_valid_limit,extdate_ExpiryDate)" />
                                                </Listeners>
                                            </ext:DateField>
                                            <ext:DateField ID="extdate_DisinfectionDate" runat="server" AnchorHorizontal="0.95"
                                                FieldLabel="<font color='red' >*</font>消毒日期" AllowBlank="false" EmptyText="输入日期格式(年-月-日)：2015-01-01" TabIndex="6">
                                                <Listeners>
                                                    <Change Handler="tmsValueChange(newValue,extspin_asepsis_limit,extdate_AsepticDate)" />
                                                    <Select Handler="tmsValueChange(date,extspin_asepsis_limit,extdate_AsepticDate)" />
                                                </Listeners>
                                            </ext:DateField>
                                        </Items>
                                    </ext:Container>
                                    <ext:Container ID="Container3" runat="server" LabelAlign="Right" Layout="FormLayout" ColumnWidth="0.5">
                                        <Items>
                                            <ext:TextField ID="exttxtf_Spec" runat="server" AnchorHorizontal="0.95" FieldLabel="规格"
                                                ReadOnly="true" StyleSpec="background:#fffbf0;" />
                                            <ext:TextField ID="exttxtf_Version" runat="server" AnchorHorizontal="0.95" FieldLabel="型号"
                                                ReadOnly="true" StyleSpec="background:#fffbf0;" />
                                            <ext:TextField ID="exttxtf_Area" runat="server" AnchorHorizontal="0.95" FieldLabel="产地"
                                                ReadOnly="true" StyleSpec="background:#fffbf0;" />
                                            <ext:TextField ID="exttxtf_Unit" runat="server" AnchorHorizontal="0.95" FieldLabel="计量单位"
                                                ReadOnly="true" StyleSpec="background:#fffbf0;" />
                                            <ext:NumberField ID="extnumf_Supplyprice" runat="server" AnchorHorizontal="0.95" DecimalPrecision="2"
                                                FieldLabel="供应单价" ReadOnly="true" StyleSpec="background:#fffbf0;" />
                                            <ext:TextField ID="exttxtf_CargoCode" runat="server" AnchorHorizontal="0.95" FieldLabel="商品编码"
                                                ReadOnly="true" StyleSpec="background:#fffbf0;" />
                                            <%--<ext:TextField ID="exttxtf_UseNAME" runat="server" AnchorHorizontal="0.95" FieldLabel="医材类别"
                                                ReadOnly="true" StyleSpec="background:#fffbf0;" />--%>
                                            <ext:CompositeField ID="CompositeField_valid_date" runat="server" AnchorHorizontal="0.95"  FieldLabel="<input name='cbox' type='checkbox' checked onclick='check_valid_date(this);'  />有效期" >
                                                <Items>
                                                    <ext:SpinnerField ID="extspin_valid_limit" runat="server" Text="12" AnchorHorizontal="0.95" MinValue="0" MaxValue="240" AllowDecimals="true" DecimalPrecision="1"
                                                        IncrementValue="1" Accelerate="true" AlternateIncrementValue="2.1" Width="60" >
                                                        <Listeners>
                                                            <Change Handler="limitValueChange(newValue,extdate_ProduceDate,extdate_ExpiryDate);" />
                                                            <Spin Handler="limitValueChange(this.getValue(),extdate_ProduceDate,extdate_ExpiryDate);" />
                                                            <Focus Handler="extBtn_Save.disable();Button2.disable();" />
                                                            <Blur Handler="extBtn_Save.enable(); Button2.enable();" />
                                                        </Listeners>
                                                    </ext:SpinnerField>
                                                    <ext:DisplayField ID="disp_text1" runat="server" Text="个月 至" Width="45" />
                                                    <ext:DateField ID="extdate_ExpiryDate" runat="server" Editable="false" Flex="1" >
                                                        <Listeners>
                                                            <Change Handler="tmeValueChange(newValue,extspin_valid_limit,extdate_ProduceDate);" />
                                                        </Listeners>
                                                    </ext:DateField>
                                                    <ext:DisplayField ID="disp_CQYX1" runat="server" Text="长期有效" Width="60" Hidden="true" />
                                                </Items>
                                            </ext:CompositeField>
                                            <ext:CompositeField ID="CompositeField_asepsis_date" runat="server" AnchorHorizontal="0.95"  FieldLabel="无菌有效期" >
                                                <Items>
                                                    <ext:SpinnerField ID="extspin_asepsis_limit" runat="server" Text="12" AnchorHorizontal="0.95" MinValue="0" MaxValue="240" AllowDecimals="true" DecimalPrecision="1"
                                                        IncrementValue="1" Accelerate="true" AlternateIncrementValue="2.1" Width="60" >
                                                        <Listeners>
                                                            <Change Handler="limitValueChange(newValue,extdate_DisinfectionDate,extdate_AsepticDate);" />
                                                            <Spin Handler="limitValueChange(this.getValue(),extdate_DisinfectionDate,extdate_AsepticDate);" />
                                                            <Focus Handler="extBtn_Save.disable();Button2.disable();" />
                                                            <Blur Handler="extBtn_Save.enable(); Button2.enable();" />
                                                        </Listeners>
                                                    </ext:SpinnerField>
                                                    <ext:DisplayField ID="disp_text2" runat="server" Text="个月 至" Width="45" />
                                                    <ext:DateField ID="extdate_AsepticDate" runat="server" Editable="false" Flex="1" >
                                                        <Listeners>
                                                            <Change Handler="tmeValueChange(newValue,extspin_asepsis_limit,extdate_DisinfectionDate);" />
                                                        </Listeners>
                                                    </ext:DateField>
                                                </Items>
                                            </ext:CompositeField>
                                        </Items>
                                    </ext:Container>
                                </Items>
                            </ext:Container>
                        </Content>
                    </ext:FormPanel>
                </Center>
            </ext:BorderLayout>
        </Content>
    </ext:Viewport>
    <ext:Hidden runat="server" ID="exthid_ItemlId" />
    <ext:Hidden runat="server" ID="exthid_supplier" />
    <ext:Hidden runat="server" ID="exthid_storeroom" />
    <ext:Hidden runat="server" ID="Hidden1" />
    </form>
</body>
</html>
